package codeTop;

public class q209 {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int slow = 0;
        int sum = 0;
        int res = Integer.MAX_VALUE;
        for (int fast = 0;fast<n;fast++){
            sum+=nums[fast];
            while (sum >= target) {
                res = Math.min(fast-slow+1,res);
                if (slow < fast) {
                    sum-=nums[slow++];
                }else {
                    break;
                }
            }
        }
        return res==Integer.MAX_VALUE?0:res;
    }
}
